/**
 * Copyright 2009-2011 xiaonei.com All right reserved.
 * This software is the confidential and proprietary information of Xiaonei.com ("Confidential Information"). 
 * You shall not disclose such Confidential Information and shall use it only in accordance with the terms of the license agreement you entered into with Xiaonei.com.
 * Create by XiaoNeiAntiSpamTeam
 *
 */

package com.xiaonei.testice.testicestorm.subscriber;

import java.util.Map;

import Ice.Communicator;
import Ice.ObjectAdapter;
import Ice.ObjectPrx;
import IceStorm.AlreadySubscribed;
import IceStorm.BadQoS;
import IceStorm.NoSuchTopic;
import IceStorm.TopicManagerPrx;
import IceStorm.TopicManagerPrxHelper;
import IceStorm.TopicPrx;

import com.xiaonei.testice.util.IceUtil;

/**
 * @ClassName: HelloWorldSubscriber
 * @Description: HelloWorld的订阅者
 * @author shaohui.liu shaohui.liu@opi-corp.com
 * @date Feb 1, 2010 6:38:43 PM
 * 
 */
public class HelloWorldSubscriber {

    public HelloWorldSubscriber() {
        Communicator co = Ice.Util.initialize(IceUtil.initData());
        
        ObjectPrx objectPrx = co.stringToProxy("TopicManager.Proxy");
        
        TopicManagerPrx topicManagerPrx = TopicManagerPrxHelper.checkedCast(objectPrx);
        
        ObjectAdapter objectAdapter = co.createObjectAdapter("HelloWorld");
        
        ObjectPrx sub = objectAdapter.addWithUUID(new HelloWorldI()).ice_oneway();

        TopicPrx topicPrx = null;

        try {
            topicPrx = topicManagerPrx.retrieve("HelloWorld");
            Map<String, String> qos = null;
            try {
                topicPrx.subscribeAndGetPublisher(qos, sub);
            } catch (AlreadySubscribed e1) {
                e1.printStackTrace();
            } catch (BadQoS e1) {
                e1.printStackTrace();
            }
        } catch (NoSuchTopic e) {
            e.printStackTrace();
        }
        objectAdapter.activate();

        co.waitForShutdown();
        //topicPrx.unsubscribe(sub);
    }
}
